

package com.hazelcast.internal.jmx;

import com.hazelcast.instance.impl.HazelcastInstanceImpl;
import com.hazelcast.logging.impl.LoggingServiceImpl;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

import static com.hazelcast.internal.jmx.ManagementService.quote;

public class LoggingServiceMBean extends HazelcastMBean<LoggingServiceImpl> {

    protected LoggingServiceMBean(HazelcastInstanceImpl hazelcastInstance, ManagementService service) {
        super((LoggingServiceImpl) hazelcastInstance.getLoggingService(), service);

        Map<String, String> properties = new HashMap<>();
        properties.put("type", quote("HazelcastInstance.LoggingService"));
        properties.put("name", quote(hazelcastInstance.getName()));
        properties.put("instance", quote(hazelcastInstance.getName()));

        setObjectName(properties);
    }

    @ManagedAnnotation("level")
    @ManagedDescription("Current level set")
    public String getLevel() {
        Level level = managedObject.getLevel();
        return level == null ? null : level.getName();
    }

    @ManagedAnnotation(value = "setLevel", operation = true)
    @ManagedDescription("Set level")
    public void setLevel(String level) {
        managedObject.setLevel(level);
    }

    @ManagedAnnotation(value = "resetLevel", operation = true)
    @ManagedDescription("Reset level")
    public void resetLevel() {
        managedObject.resetLevel();
    }

}
